var app = require('express')();
var bodyParser = require('body-parser');
//var multer = require('multer'); // v1.0.5
//var upload = multer(); // for parsing multipart/form-data
app.all('*',function(req,res,next)
{
    if (!req.get('Origin')) return next();

    res.set('Access-Control-Allow-Origin','*');
    res.set('Access-Control-Allow-Methods','GET,POST');
    res.set('Access-Control-Allow-Headers','X-Requested-With,Content-Type');

 //   if ('OPTIONS' == req.method) return res.sendStatus(200);

    next();
});
app.use(bodyParser.json()); // for parsing application/json
app.use(bodyParser.urlencoded({ extended: true })); // for parsing application/x-www-form-urlencoded

app.post('/login', function (req, res, next) {
  console.log(req.body);
  if (req.body.username === 'yy' && req.body.password === 'yyy') {
    res.json({flag:'ok'});
  }else {
    res.json({flag:'fail'});
  }
});

app.get('/yy', function (req, res) {
  res.send('hello yy');
})

app.listen(3000, function () {
  console.log('Example app listening on port 3000!');
});